package com.lagou.filter;

/**
 * @author lcy
 */
public class CountData {

    int[] scale = new int[10000];
    int[] countContainer = new int[10000];
    long totalTimes=0L;
    static CountData getInstance(){
        CountData monitorData = new CountData();
        return monitorData;
    }

    public synchronized void addTimesNum(int ms){
        this.totalTimes++;
        this.scale[ms]=ms;
        this.countContainer[ms]++;
    }

    public int statTP(float f) {
        int round = Math.round(this.totalTimes*f);
        int result=0;
        int t=0;
        for (int i=0;i<countContainer.length;i++) {
            t+=countContainer[i];
            if(t>=round){
                result=  scale[i];
                break;
            }
        }
        return result;
    }

    public long getTotalTimes() {
        return totalTimes;
    }

}
